<?php
class SectionModel extends RelationModel{
	
	/**
	 * 
	 * 定义关联关系
	 * 
	 */
	protected $_link = array(
		'Category' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'Category',
			'foreign_key' => 'sectionid',
			'mapping_name' => 'categorys',
			'mapping_order' => 'sectionid desc',
		),
		'Article' => array(
			'mapping_type' => HAS_MANY,
			'class_name' => 'Article',
			'foreign_key' => 'sectionid',
			'mapping_name' => 'articles',
			'mapping_order' => 'sectionid desc',
		),
		
		
	);
	
	
	
	/**
	 * 表单数据验证
	 */
	protected $_validate = array(
		array('title','require','单元名称必须填写!',1,'regex',3),
		
	);
	
	
	/**
	 * 自动填充
	 */
	protected  $_auto = array(
		array('alias','getAlias',1,'callback'),
	);
	
	function getAlias(){
		if(empty($_POST['alias'])){
			return date('Y-m-d-H-i-s');
		}else{
			return $_POST['alias'];
		}
	}
	
	/**
	 * 字段映射
	 */
	protected $_map = array();
}

?>
